//处理登录的数据和服务器端交互
var loginManager = {};

loginManager.login = function () {
    $.ajax({
        url:'/LoginServlet',
        type:'post',
        data:{
            "loginName":$("#loginName").val(),
            "loginPwd":$("#loginPwd").val()
        },
        dataType:'json',
        success:function (res) {
            var result = res.data;
            alert(result.staffId)
            if (res.status > 0) {
                    toastr['success']("登录成功");

                // 在应用持久化数据
                window.localStorage.setItem("loginName",result.staffName);
                window.localStorage.setItem("staffId",result.staffId);
                window.localStorage.setItem("id",result.roleId);
                window.localStorage.setItem("phone",result.phone);
                window.localStorage.setItem("idCard",result.idCard);
                window.localStorage.setItem("address",result.address);
                window.localStorage.setItem("createdTime",result.createdTime);
                window.localStorage.setItem("password",result.password);
                window.location.href = "../index/views/main.html";

            }else {
                toastr['error']("登录失败");
            }
        }
    })
}